﻿using System.ComponentModel.DataAnnotations;

namespace AiQiuQuan.Sport.Model.Models
{
    /// <summary>
    /// 俱乐部部活动新增DTO
    /// </summary>
    public class ClubActivityAddDto : IValidatableObject
    {
        /// <summary>
        /// 俱乐部ID
        /// </summary>
        [Required(ErrorMessage = "俱乐部ID必填")]
        public Guid ClubId { get; set; }

        /// <summary>
        /// 地点
        /// </summary>
        [Required(AllowEmptyStrings = false, ErrorMessage = "地点必填")]
        public string Address { get; set; }

        /// <summary>
        /// 开始日期
        /// </summary>
        [Required(ErrorMessage = "开始日期必填")]
        public DateTimeOffset StartDate { get; set; }

        /// <summary>
        /// 开始时间: 08:00
        /// </summary>
        [Required(AllowEmptyStrings = false, ErrorMessage = "开始时间: 08:00必填")]
        public string StartTime { get; set; }

        /// <summary>
        /// 结束时间：18:00
        /// </summary>
        [Required(AllowEmptyStrings = false, ErrorMessage = "结束时间：18:00必填")]
        public string EndTime { get; set; }

        /// <summary>
        /// 参赛人数
        /// </summary>
        [Required(ErrorMessage = "参赛人数必填")]
        public int LimitCount { get; set; }

        /// <summary>
        /// 金额
        /// </summary>
        [Required(ErrorMessage = "金额必填")]
        public decimal Amount { get; set; }

        /// <summary>
        /// validate
        /// </summary>
        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            if (Amount <= 0)
            {
                yield return new ValidationResult("活动金额小于等于0");
                yield break;
            }

            if (LimitCount <= 0)
            {
                yield return new ValidationResult("活动人数小于等于0");
                yield break;
            }

            if (!TimeSpan.TryParse(StartTime, out var start))
            {
                yield return new ValidationResult("活动开始时间格式错误：ex 08:00");
                yield break;
            }

            if (!TimeSpan.TryParse(EndTime, out var end))
            {
                yield return new ValidationResult("活动结束时间格式错误：ex 18:00");
                yield break;
            }

            if (start >= end)
            {
                yield return new ValidationResult("活动开始时间大于等于结束时间");
                yield break;
            }
        }
    }
}
